package com.baiyun.controller.user;


import com.baiyun.Result.Result;
import com.baiyun.entity.Orders;
import com.baiyun.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user/orders")
@RequiredArgsConstructor
@Api(tags = "客户端端——下单管理")
public class UserOrdersController {
    private final OrderService orderService;

    /**
     * 查询所有订单
     * @return
     */
    @GetMapping()
    @ApiOperation("查询所有订单")
    public Result<List<Orders>> selectAllOrder(){
        log.info("查询所有订单");
        return Result.success(orderService.selectAllOrder());
    }

    /**
     * 添加订单
     * @return
     */
    @PostMapping()
    @ApiOperation("添加订单")
    public Result<List<Orders>> UserAddOrder(@RequestBody Orders orders){
        log.info("添加订单");
        orderService.UserAddOrder(orders);
        return Result.success();
    }

    /**
     * 修改订单
     * @param orders
     * @return
     */
    @PutMapping()
    @ApiOperation("修改订单")
    public Result updateOrder(@RequestBody Orders orders){
        log.info("修改订单");
        orderService.updateOrder(orders);
        return Result.success();
    }

    /**
     * 删除订单
     * @param oid
     * @return
     */
    @DeleteMapping ("/{oid}")
    @ApiOperation("删除订单")
    public Result deleteOrder(@ApiParam("订单id")@PathVariable Integer oid){
        log.info("删除订单");
        orderService.deleteOrder(oid);
        return Result.success();
    }

    /**
     * 根据ID查询订单
     * @param oid
     * @return
     */
    @GetMapping ("/{oid}")
    @ApiOperation("根据ID查询订单")
    public Result<Orders> selectById(@ApiParam("订单id")@PathVariable("oid") Integer oid){
        log.info("根据ID查询订单");
        return Result.success(orderService.selectById(oid));
    }


    /**
     * 根据茶名模糊搜索订单
     * @param
     * @return
     */
    @GetMapping ("/search/{tname}")
    @ApiOperation("根据茶名模糊搜索订单")
    public Result<List<Orders>> slectByTeaName(@ApiParam("茶名")@PathVariable("tname") String tname){
        log.info("根据茶名模糊搜索订单");
        return Result.success(orderService.slectByTeaName(tname));
    }
}
